package y_2025.m06.d27;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class DietPlanner {

    // 定义食物类，类似C++中的结构体
    static class Food {
        int fat;      // 食物脂肪含量
        int category; // 食物类别
        
        public Food(int fat, int category) {
            this.fat = fat;
            this.category = category;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // 输入基本参数
        int totalFoods = scanner.nextInt();
        int maxPerMeal = scanner.nextInt();
        int totalCategories = scanner.nextInt();
        
        // 每类食物限制数组（索引1开始）
        int[] categoryLimit = new int[totalCategories + 1];
        for (int i = 1; i <= totalCategories; i++) {
            categoryLimit[i] = scanner.nextInt();
        }
        
        // 创建食物数组并初始化
        Food[] foods = new Food[totalFoods];
        for (int i = 0; i < totalFoods; i++) {
            int fat = scanner.nextInt();
            int category = scanner.nextInt();
            foods[i] = new Food(fat, category);
        }
        
        // 按脂肪含量从高到低排序
        Arrays.sort(foods, new Comparator<Food>() {
            @Override
            public int compare(Food a, Food b) {
                return Integer.compare(b.fat, a.fat); // 降序排序
            }
        });
        
        int ans = 0; // 最大脂肪总和
        int chosenCount = 0; // 已选食物计数
        int[] chosenPerCategory = new int[totalCategories + 1]; // 每类已选计数
        
        // 从高脂肪食物开始选择
        for (int i = 0; i < totalFoods; i++) {
            int cat = foods[i].category;
            
            // 检查是否还能选择食物，并且该类别还有剩余配额
            if (chosenCount < maxPerMeal && chosenPerCategory[cat] < categoryLimit[cat]) {
                ans += foods[i].fat;          // 累加脂肪含量
                chosenCount++;                 // 增加已选食物计数
                chosenPerCategory[cat]++;      // 增加该类已选食物计数
            }
        }
        
        // 输出最大脂肪总和
        System.out.println(ans);
    }
}